<?php

/**
 * 生成随机字符串
 * @param int $length
 * @return string
 */
function getRand( $length = 32 )
{
    $str='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $len=strlen($str)-1;
    $randStr='';
    for($i=0;$i<$length;$i++){
        $num=mt_rand(0,$len);
        $randStr .= $str[$num];
    }
    return $randStr;
}

/**
 * 模拟生成优选订单号
 * 规则：DD（订单）+商品分类编号（9位）+时间（年月日6位）+流水号（6位）
 * 例子：DDF01S01T01180704000001
 * @return string
 */
function createYxOrderNo()
{
    $goodsCatIdList = [1,2,3];
    $time = substr(date('Ymd',time()),2);
    $orderNo = 'DDF'.$goodsCatIdList[0].'S'.$goodsCatIdList[1].'T'.$goodsCatIdList[2].$time;
    return $orderNo.getRand(6);
}

/**
 * 随机返回一个内部员工id作为虚假order的购买人
 * @return mixed
 */
function getRandCustomerIdForGiftCommission() {

    $customerIdList = [207,18,19,219,14,880,235,24,15,16,20,209,22,248,21,208,211,2951];
    shuffle($customerIdList);

    return $customerIdList[0];

}

/**
 * 随机返回商品信息作为虚假order的商品
 * @return mixed
 */
function getRandGoodsInfoForGiftCommission() {

    $goodsList = [

        [
            "goods_id" => 93,
            "goods_img" => "https://image-xinke.xinker.me/5b7a627994879.jpg",
            "goods_name" => "懒人神器O2泡 | 浸泡10分钟，相当于搓洗数千次",
            "price" => 64,
            "commission" => 6.4
        ],

        [
            "goods_id" => 113,
            "goods_img" => "https://image-xinke.xinker.me/5b7a9b5d64c65.jpg",
            "goods_name" => "小海马 | 孩子早教益智好伙伴，轻柔音乐助睡眠",
            "price" => 66.9,
            "commission" => 6.69
        ],

        [
            "goods_id" => 205,
            "goods_img" => "https://image-xinke.xinker.me/5ba31519521e6.jpg",
            "goods_name" => "蓝月亮洗衣液 | 科学洗衣巧搭配，凝炼超凡能量",
            "price" => 47.9,
            "commission" => 4.79
        ],

        [
            "goods_id" => 272,
            "goods_img" => "https://image-xinke.xinker.me/5beab08b098c1.jpg",
            "goods_name" => "红心蜜柚 | 苦尽甘来，每粒果肉透着鲜美",
            "price" => 47,
            "commission" => 4.7
        ],

    ];

    shuffle($goodsList);

    return $goodsList[0];

}

function formatAccountDetailTime($dateTime) {

    $createTime = date("m/d", strtotime($dateTime));

    $formatTime = $createTime;
    if ($createTime == date("m/d")) {
        $formatTime = '今日';
    }

    $diffDay = timeDiff(strtotime(date("Y-m-d")),
        strtotime($createTime));

    if ($diffDay['day'] == 1) {
        $formatTime = '昨日';
    }

    if (date("Y", strtotime($dateTime)) != date("Y")) {
        $formatTime = date("Y/m/d", strtotime($dateTime));
    }

    return $formatTime;
}
